package com.horoscope.astrology.zodiac.signs.free.utils

import com.horoscope.astrology.zodiac.signs.free.R
import com.horoscope.astrology.zodiac.signs.free.bean.ConstellationBean
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList

object ConstellationUtil {

    val dayStart = intArrayOf(20, 20, 19, 20, 19, 20, 21, 22, 22, 22, 23, 21) // 两个星座分割日以结束日期（从射手开始）

    val starArr = arrayOf(
        "魔羯座",
        "水瓶座",
        "双鱼座",
        "牡羊座",
        "金牛座",
        "双子座",
        "巨蟹座",
        "狮子座",
        "处女座",
        "天秤座",
        "天蝎座",
        "射手座"
    )

    val starNameInEnglish = arrayOf(
        "Capricorn",
        "Aquarius",
        "Pisces",
        "Aries",
        "Taurus",
        "Gemini",
        "Cancer",
        "Leo",
        "Virgo",
        "Libra",
        "Scorpio",
        "Sagittarius"
    )

    private val constellationIcon = intArrayOf(
        R.mipmap.icon_capricorn,
        R.mipmap.icon_aquarius,
        R.mipmap.icon_pisces,
        R.mipmap.icon_aries,
        R.mipmap.icon_taurus,
        R.mipmap.icon_gemini,
        R.mipmap.icon_cancer,
        R.mipmap.icon_leo,
        R.mipmap.icon_virgo,
        R.mipmap.icon_libra,
        R.mipmap.icon_scorpio,
        R.mipmap.icon_sagittarius
    )

    private val compatibilityTitleIcon = intArrayOf(
        R.mipmap.icon_title_capricorn,
        R.mipmap.icon_title_aquarius,
        R.mipmap.icon_title_pisces,
        R.mipmap.icon_title_aries,
        R.mipmap.icon_title_taurus,
        R.mipmap.icon_title_gemini,
        R.mipmap.icon_title_cancer,
        R.mipmap.icon_title_leo,
        R.mipmap.icon_title_virgo,
        R.mipmap.icon_title_libra,
        R.mipmap.icon_title_scorpio,
        R.mipmap.icon_title_sagittarius
    )

    val iconApp = mapOf(
        Pair("Aries", R.mipmap.icon_aries),
        Pair("Taurus", R.mipmap.icon_taurus),
        Pair("Gemini", R.mipmap.icon_gemini),
        Pair("Cancer", R.mipmap.icon_cancer),
        Pair("Leo", R.mipmap.icon_leo),
        Pair("Virgo", R.mipmap.icon_virgo),
        Pair("Libra", R.mipmap.icon_libra),
        Pair("Scorpio", R.mipmap.icon_scorpio),
        Pair("Sagittarius", R.mipmap.icon_sagittarius),
        Pair("Capricorn", R.mipmap.icon_capricorn),
        Pair("Aquarius", R.mipmap.icon_aquarius),
        Pair("Pisces", R.mipmap.icon_pisces)
    )


    val iconTitleBgMap = mapOf(
        Pair("Aries", R.mipmap.icon_title_aries),
        Pair("Taurus", R.mipmap.icon_title_taurus),
        Pair("Gemini", R.mipmap.icon_title_gemini),
        Pair("Cancer", R.mipmap.icon_title_cancer),
        Pair("Leo", R.mipmap.icon_title_leo),
        Pair("Virgo", R.mipmap.icon_title_virgo),
        Pair("Libra", R.mipmap.icon_title_libra),
        Pair("Scorpio", R.mipmap.icon_title_scorpio),
        Pair("Sagittarius", R.mipmap.icon_title_sagittarius),
        Pair("Capricorn", R.mipmap.icon_title_capricorn),
        Pair("Aquarius", R.mipmap.icon_title_aquarius),
        Pair("Pisces", R.mipmap.icon_title_pisces)
    )

    val name = mapOf(
        Pair("Aries", "03/21 - 04/19"),
        Pair("Taurus", "04/20 - 05/20"),
        Pair("Gemini", "05/21 - 06/21"),
        Pair("Cancer", "06/22 - 07/22"),
        Pair("Leo", "07/23 - 08/22"),
        Pair("Virgo", "08/23 - 09/22"),
        Pair("Libra", "09/23 - 10/23"),
        Pair("Scorpio", "10/24 - 11/21"),
        Pair("Sagittarius", "11/22 - 12/20"),
        Pair("Capricorn", "12/21 - 01/20"),
        Pair("Aquarius", "01/21 - 02/19"),
        Pair("Pisces", "02/20 - 3/20")
    )

    val map = mapOf(
        Pair("Aries", "3.21 - 4.19"),
        Pair("Taurus", "4.20 - 5.20"),
        Pair("Gemini", "5.21 - 6.21"),
        Pair("Cancer", "6.22 - 7.22"),
        Pair("Leo", "7.23 - 8.22"),
        Pair("Virgo", "8.23 - 9.22"),
        Pair("Libra", "9.23 - 10.23"),
        Pair("Scorpio", "10.24 - 11.21"),
        Pair("Sagittarius", "11.22 - 12.20"),
        Pair("Capricorn", "12.21 - 1.20"),
        Pair("Aquarius", "1.21 - 2.19"),
        Pair("Pisces", "2.20 - 3.20")
    )

    fun getConstellationList(): ArrayList<ConstellationBean> {
        val list = ArrayList<ConstellationBean>()
//        var i = 0
        name.forEach {
            val bean = ConstellationBean()
            bean.name = it.key
            bean.time = it.value
//            bean.drawableId = iconApp[it.key] ?: error("")
            list.add(bean)
        }
        return list
    }

    // 灰色
    fun getDrawableIdByName(name: String): Int {
        return if (iconTitleBgMap[name] == null) {
            R.mipmap.icon_title_leo
        } else {
            iconTitleBgMap[name] ?: error("")
        }
    }

    // 彩色
    fun getIconByName(name: String): Int {
        return if (iconApp[name] == null) {
            R.mipmap.icon_pisces
        } else {
            iconApp[name] ?: error("")
        }
    }

    fun getDateByName(name: String): String {
        return if (map[name] == null) {
            "02.19 - 3.20"
        } else {
            map[name] ?: error("")
        }

    }

    fun getMagicTip(): String {
        val random = (0..22).random()
        val tips = arrayOf(
            "It's fate.",
            "PROBABLY",
            "ONLY TIME WILL TELL", "",
            "Don 't count on it",
            "It is certain",
            "It is decidedly so",
            "Without a doubt",
            "Yes, definitely",
            "You may rely on it",
            "As I see it, yes",
            "Most likely",
            "Outlook good",
            "Yes",
            "Signs point to yes",
            "Reply hazy try again",
            "Ask again later",
            "Better not tell you now",
            "Cannot predict now",
            "Concentrate and ask again",
            "My reply is no:",
            "My sources say no",
            "Outlook not so good",
            "Very doubtful"
        )
        return tips[random]
    }

    fun getAdConfig(): String {
        return "{\"ADConfig\":{" +
                "\"Admob\":{\"AppID\":\"ca-app-pub-7568473909272637~5237511820\"}," +
                "\"IronSource\":{\"AppID\":\"bb260c25\"}}," +
                "\"ADID\":{" +
                "\"Interstitial\":[" +
                "[{\"advertiser\":\"Facebook\",\"cpminfo\":\"30\",\"id\":\"689949925164662_695661061260215\"}]," +

                "[{\"advertiser\":\"Admob\",\"cpminfo\":\"20\",\"id\":\"ca-app-pub-7568473909272637/3389351330\"}," +
                "{\"advertiser\":\"Facebook\",\"cpminfo\":\"19\",\"id\":\"689949925164662_695661497926838\"}," +
                "{\"advertiser\":\"IronSource\",\"id\":\"2352293\",\"cpminfo\":\"18\",\"placement\":\"HS_A_G1_IronInterstitial_0402\"}]," +

//                "[{\"advertiser\":\"Admob\",\"cpminfo\":\"17\",\"id\":\"ca-app-pub-7568473909272637/9763187995\"}]," +

                "[{\"advertiser\":\"Admob\",\"cpminfo\":\"15\",\"id\":\"ca-app-pub-7568473909272637/2684636146\"}," +
                "{\"advertiser\":\"IronSource\",\"id\":\"2377087\",\"cpminfo\":\"9\",\"id\":\"HS_A_G2_IronInterstitial_0402\"}," +
                "{\"advertiser\":\"Facebook\",\"cpminfo\":\"10\",\"placement\":\"689949925164662_69566170126015\"}]," +

//                "[{\"advertiser\":\"Admob\",\"cpminfo\":\"10\",\"id\":\"ca-app-pub-7568473909272637/2684636146\"}," +
//                "{\"advertiser\":\"Facebook\",\"cpminfo\":\"9\",\"id\":\"689949925164662_695661701260151\"}]," +

                "[{\"advertiser\":\"IronSource\",\"id\":\"2757577\",\"cpminfo\":\"9\",\"id\":\"HS_A_G2_IronInterstitial_0402\"}," +
                "{\"advertiser\":\"Facebook\",\"cpminfo\":\"4\",\"id\":\"689949925164662_760444621448525\"}]]," +

                "\"Native\":[" +
                "[{\"advertiser\":\"Facebook\",\"cpminfo\":\"30\",\"id\":\"689949925164662_689985308494457\"}]," +

                "[{\"advertiser\":\"Admob\",\"cpminfo\":\"14\",\"id\":\"ca-app-pub-7568473909272637/9988411092\"}," +
                "{\"advertiser\":\"Admob\",\"cpminfo\":\"8\",\"id\":\"ca-app-pub-7568473909272637/7170676060\"}," +
                "{\"advertiser\":\"Facebook\",\"cpminfo\":\"9\",\"id\":\"689949925164662_689987408494247\"}]," +

                "[{\"advertiser\":\"Admob\",\"cpminfo\":\"4\",\"id\":\"ca-app-pub-7568473909272637/3663865260\"}," +
                "{\"advertiser\":\"Facebook\",\"cpminfo\":\"3\",\"id\":\"689949925164662_689987551827566\"}]]," +

                "\"Reward\":[" +
//                {\"advertiser\":\"Admob\",\"cpminfo\":\"15\",\"id\":\"ca-app-pub-7568473909272637/1776068527\"}," +
                "[{\"advertiser\":\"IronSource\",\"id\":\"2352257\",\"cpminfo\":\"15\",\"placement\":\"HS_A_G1_IronRewardedVideo_0402\"}]," +

                "[{\"advertiser\":\"Admob\",\"cpminfo\":\"8\",\"id\":\"ca-app-pub-7568473909272637/6645251824\"}," +
                "{\"advertiser\":\"IronSource\",\"id\":\"2377085\",\"cpminfo\":\"9\",\"id\":\"HS_A_G2_IronRewardedVideo_0402\"}]," +

                "[{\"advertiser\":\"Admob\",\"cpminfo\":\"4\",\"id\":\"ca-app-pub-7568473909272637/2499466526\"}," +
                "{\"advertiser\":\"IronSource\",\"id\":\"2757577\",\"cpminfo\":\"3\",\"placement\":\"HS_A_G1_IronRewardedVideo_0402\"}]]" +

                "},\"message\":\"\",\"status\":\"\"}"
    }

    fun getFortuneTip(): String {
        val tips = arrayOf(
            "Happiness may be right under your nose.",
            "Don't wait for setSuccess to come - go find it!",
            "Work with what you have.",
            "Fall for someone who's not your type.",
            " To be idle is to be foolish.",
            "Work with your destiny. Stop trying to outrun it.",
            "Your home will be filled with peace and harmony.",
            "Don't worry what others think of you.",
            "Someone thinks the world of you.",
            "Your smile lights up someone else's day.",
            "A healthy body will benefit you for life.",
            "Fame and fortune lie ahead.",
            "Don't hesitate to tackle a difficult problem.",
            "Work first, but make sure to play later.",
            "Don't wait for setSuccess to come - go find it!",
            "Learn how to do something new today.",
            "Look in the mirror without admiring your reflection.",
            "Do your job to the best of your ability.",
            "An exciting adventure awaits you.",
            "Show everyone what you can do.",
            "Tomorrow is another day.",
            "Everything has beauty, but not everyone can see it.",
            "Go with your gut feeling.",
            "Stop procrastinating. Make a decision already.",
            "Worry does not beget change.",
            "Don't hesitate to tackle a difficult problem.",
            "Pay attention to your family. Don't take them for granted.",
            "Face the truth with dignity.",
            "You have good reason to be self-confident.",
            "Be thankful, even if your life is not perfect.",
            "You will do well to advance your career.",
            "Learn from your mistakes. Try not to make them again.",
            "It may be difficult, but it will be worth it in the end.",
            "The dream is within you.",
            "Dream your dream and your dream will dream of you.",
            "Encourage your peers."
        )
        val random = (0..35).random()
        return tips[random]

    }

    /**
     * 根据日期字符串提取月数字
     */
    fun getMonthFromStringDate(data: String?): Int {
        val sdf = SimpleDateFormat("MM-dd-yyyy")
        val calendar = Calendar.getInstance()
        try {
            val date = sdf.parse(data)
            calendar.time = date
        } catch (e: ParseException) {
            e.printStackTrace()
        }
        return calendar[Calendar.MONTH] + 1
    }

    /**
     * 根据日期字符串提取天数字
     */
    fun getDayFromStringDate(data: String?): Int {
        val sdf = SimpleDateFormat("MM-dd-yyyy")
        val calendar = Calendar.getInstance()
        try {
            val date = sdf.parse(data)
            calendar.time = date
        } catch (e: ParseException) {
            e.printStackTrace()
        }
        return calendar[Calendar.DAY_OF_MONTH]
    }

    // 根绝日期获取星座名
    fun getConstellationName(month: Int, day: Int): String {
        var index = month //[0,11]

        // 所查询日期在分割日之前
        if (day > dayStart[(month + 1) % 12]) {
            index = (index + 1) % 12
        }

        return starNameInEnglish[index]
    }

    // 根据日期获取星座图标
    fun getConstellationDrawable(month: Int, day: Int, type: Int): Int {
        var index = month //[0,11]

        // 所查询日期在分割日之前
        if (day > dayStart[(month + 1) % 12]) {
            index = (index + 1) % 12
        }
        // 透明1 彩色 其它
        return if (type == 1) compatibilityTitleIcon[index] else constellationIcon[index]
    }
}